//
//  ViewController.m
//  ForTest
//
//  Created by liboxiang on 2019/3/22.
//  Copyright © 2019 liboxiang. All rights reserved.
//

#import "ViewController.h"
#import "TYPersistenceController.h"
#import "Lbx+CoreDataProperties.h"
#import "ManagedObjectHelper.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    [TYPersistenceController createtWithSqliteName:@"forTest.sqlite" modelName:@"ForTest" userID:@"common"];
//    NSArray *uidArray = @[@"liboxiang1", @"lihaoman", @"lihuayi", @"liyuchao", @"lingyanmei", @"lingchunfeng", @"libojing", @"liyuming", @"libosong", @"liyuexuan"];
    NSArray *uidArray = @[@"liboxiang1", @"lihaoman"];
    NSMutableArray *mArray = [NSMutableArray arrayWithCapacity:uidArray.count];
    for (int i = 0; i < uidArray.count; i++) {
        NSString *name = uidArray[i];
        NSMutableDictionary *tmpDic = [NSMutableDictionary dictionaryWithCapacity:0];
        [tmpDic setObject:name forKey:@"name"];
        [tmpDic setObject:name forKey:@"uid"];
        [tmpDic setObject:@(i + 40) forKey:@"age"];
        [tmpDic setObject:@(0) forKey:@"isBoy"];
        [tmpDic setObject:@(i * 3.3 + 10) forKey:@"floatType"];
        [mArray addObject:tmpDic];
    }
    [ManagedObjectHelper mergeOrAddWithEntityName:@"Lbx" list:mArray uidKey:@"uid" groupDic:@{@"age":@(2)} ignoreKeys:@[@"floatType"] context:[TYPersistenceController shareInstance].managedObjectContext];
    [[TYPersistenceController shareInstance] saveContextAndWait:YES completion:nil];
}


@end
